package com.briup.jz.web.controller;

import com.briup.jz.bean.BaseRolePrivilege;
import com.briup.jz.bean.BaseUserRole;
import com.briup.jz.service.IBaseRolePrivilegeService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(description = "角色权限")
@RestController
@RequestMapping("/baseRolePrivilege")
public class BaseRolePrivilegeController {
    @Autowired
    private IBaseRolePrivilegeService baseRolePrivilegeService;

    @PostMapping("/save")
    @ApiOperation("给角色添加权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name="roleId",value = "角色Id",paramType = "form", required=true),
            @ApiImplicitParam(name="privilegeId",value = "权限Id",paramType = "form", required=true),
    })
    public Message save(Long roleId, Long privilegeId){
        BaseRolePrivilege baseRolePrivilege = new BaseRolePrivilege();
        baseRolePrivilege.setRoleId(roleId);
        baseRolePrivilege.setPrivilegeId(privilegeId);
        baseRolePrivilegeService.save(baseRolePrivilege);
        return MessageUtil.success("保存成功");
    }

    @ApiOperation(value = "查询角色权限")
    @GetMapping("query")
    public Message query(){
        List<BaseRolePrivilege> list = baseRolePrivilegeService.query();
        return MessageUtil.success(list);
    }

    @GetMapping("/delete")
    @ApiOperation("删除给角色赋予的权限")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message delete(Long id){
        baseRolePrivilegeService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
}
